home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
DEMON
/
RISCOS2
/
TCP_131S.ARC
/
c
/
IPDUMP
< prev
next >
Wrap
Text File
|
1992-03-05
|
2KB
|
84 lines
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "internet.h"
#include "timer.h"
#include "iface.h"
#include "ip.h"
#include "trace.h"
#include "netuser.h"
#include "tcp.h"
#include "udp.h"
#include "icmp.h"
#include "misc.h"
void ip_dump(struct mbuf **bpp, int check)
{
struct ip ip;
int16 ip_len;
int16 offset;
int16 length;
int16 csum;
if(bpp == NULLBUFP || *bpp == NULLBUF)
return;
twprintf("IP:");
/* Sneak peek at IP header and find length */
ip_len = ((*bpp)->data[0] & 0xf) << 2;
if(ip_len < IPLEN){
twprintf(" bad header\n");
return;
}
if(check)
csum = cksum(NULLHEADER,*bpp,ip_len);
else
csum = 0;
ntohip(&ip,bpp); /* Can't fail, we've already checked ihl */
/* Trim data segment if necessary. */
length = ip.length - ip_len; /* Length of data portion */
trim_mbuf(bpp,length);
twprintf(" len %u",ip.length);
twprintf(" %s",inet_ntoa(ip.source));
twprintf("->%s ihl %u ttl %u",
inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
if(ip.tos != 0)
twprintf(" tos %u",uchar(ip.tos));
offset = (ip.fl_offs & F_OFFSET) << 3;
if(offset != 0 || (ip.fl_offs & MF))
twprintf(" id %u offs %u",ip.id,offset);
if(ip.fl_offs & DF)
twprintf(" DF");
if(ip.fl_offs & MF){
twprintf(" MF");
check = 0; /* Bypass host-level checksum verify */
}
if(csum != 0)
twprintf(" CHECKSUM ERROR (%u)",csum);
if(offset != 0){
twprintf("\n");
return;
}
switch(uchar(ip.protocol)){
case TCP_PTCL:
twprintf(" prot TCP\n");
tcp_dump(bpp,ip.source,ip.dest,check);
break;
case UDP_PTCL:
twprintf(" prot UDP\n");
udp_dump(bpp,ip.source,ip.dest,check);
break;
case ICMP_PTCL:
twprintf(" prot ICMP\n");
icmp_dump(bpp,ip.source,ip.dest,check);
break;
default:
twprintf(" prot %u\n",uchar(ip.protocol));
break;
}
}